package com.weizai.carshop.controller;


import com.weizai.carshop.common.enumeration.AppHttpCodeEnum;
import com.weizai.carshop.common.result.PageResult;
import com.weizai.carshop.common.result.ResponseResult;
import com.weizai.carshop.model.dto.GoodsInfoDto;
import com.weizai.carshop.model.dto.QueryGoodsInfoDto;
import com.weizai.carshop.service.GoodsInfoService;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

@RestController
@RequestMapping("/api/v1/admin/goodsInfo")
@RequiredArgsConstructor
public class GoodsInfoController {


    private final GoodsInfoService goodsInfoService;

    /*
     * 查询商品信息
     * */
    @GetMapping
    public ResponseResult queryGoodsInfo(QueryGoodsInfoDto dto) {
        PageResult result = goodsInfoService.queryGoodsInfo(dto);
        return ResponseResult.okResult(result);
    }

    /*
     * 编辑或新增商品信息
     * */
    @PostMapping
    public ResponseResult updateGoodsInfo(@RequestBody GoodsInfoDto dto) {
        goodsInfoService.updateGoodsInfo(dto);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }

    /*
     * 删除商品信息
     * */
    @DeleteMapping("/{id}")
    public ResponseResult delGoodsInfo(@PathVariable Long id) {
        goodsInfoService.removeById(id);
        return ResponseResult.okResult(AppHttpCodeEnum.SUCCESS);
    }
}
